package my.edu.common.validate;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class IntegerPatternValidator implements ConstraintValidator<IntegerPattern, Integer> {

    private String regexp;

    @Override
    public void initialize(IntegerPattern constraintAnnotation) {
        this.regexp = constraintAnnotation.regexp();
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
//        if (value == null) {
//            return true; // 或者根据业务逻辑决定是否允许为空
//        }
        return String.valueOf(value).matches(regexp);
    }
}
